Skip to content

Add stack limit check in zend_eval_const_expr() #11424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 7, 2023

Conversation

arnaud-lb
Copy link
Member

@arnaud-lb arnaud-lb commented Jun 11, 2023

Add a stack limit check to avoid stack overflows when trying to evaluate very large expressions.

This is similar to the check in zend_compile_expr(), but instead of bailing out, we can just skip evaluation (although this still bailouts afterwards if the expression is compiled).

#ifdef ZEND_CHECK_STACK_LIMIT
if (UNEXPECTED(zend_call_stack_overflowed(EG(stack_limit)))) {
/* Abort evaluation due to stack usage. Note that compiling this
* expression is likely to also fail. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is a real problem but zend_eval_const_expr evaluates some AST nodes that must not appear again in constant expressions, e.g. magic constants. It might be better to fatal error right here too, in case the expression evaluation uses fewer stack frames than zend_eval_const_expr.

@arnaud-lb arnaud-lb marked this pull request as ready for review June 28, 2023 09:35
@arnaud-lb arnaud-lb merged commit 72a163a into php:master Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants